r 您所在的位置:网站首页 rstudio markdown导出pdf r

r

2023-10-26 18:38| 来源: 网络整理| 查看: 265

我认为我遇到了 MikTeX 问题。在 RStudio 中,我单击 Knit PDF 按钮并收到此错误消息。

这是 pdfTeX,版本 3.1415926-2.3-1.40.12(MiKTeX 2.9 64 位) pdflatex:找不到内存转储文件。 pdflatex:数据:pdflatex.fmt

然后我按照 http://docs.miktex.org/manual/formats.html 上的第一条指令进行操作 然后我重新启动了计算机。

此时我不知道是否需要添加内存转储文件,如果需要,具体如何操作的详细信息。

然后我尝试了 Knit Word,效果非常好,生成了 Word 2007 文档。

我正在使用 RStudio。我有一个 R 标记文档 Ira.Rmd。它生成文件 Ira.md 和 Ira.html。我想另存为 Ira.pdf。我下载并在命令行上运行 pandoc

pandoc Ira.md –o Ira.pdf.

我收到以下错误消息。

Pandoc:从 TeX 源生成 PDF 时出错。 这是 pdfTeX,版本 3.1415926-2.3.1.40.12 Pdlatex:找不到内存转储文件。 Pdlatex:数据:pdflatex.fmt

有人可以简单地解释一下如何执行此文件转换吗? 我正在使用以下内容。

Windows 7。 R版本:3.0.2 RStudio 版本:0.98.684

我确实读过https://github.com/rstudio/rmarkdown但我仍然不明白如何转换我的文件。

更新我正在编辑我的问题。

我正在尝试将 R markdown 文件转换为 PDF。我在 R Studio 中创建了 RMD 文件。单击按钮,我成功生成了充满 R 代码的 HTML 文件。

我使用的是 R 版本 3.0.2

我使用的是 RStudio 版本 0.98.684

我不知道以下内容是否相关。

我的 .Rprofile 文件包含以下行。

setwd("C:/Users/Ira/Documents/Statistics")

我运行了以下内容

> getwd() [1] "C:/Users/Ira/Documents/Statistics"

我已经尝试了所有建议。谢谢。但是,在尝试转换为 PDF 时,我继续收到错误消息。我最近的帖子试图发布错误消息。

真正的Rmarkup文件是:IraAppliedStats.Rmd

单击 Knit 会生成所需的 HTML 文件。

我成功运行了命令:

install.packages("devtools"); devtools::install_github("rstudio/rmarkdown") library(rmarkdown)

我从控制台运行了以下命令,但收到错误。

render(input = "toPDF2.rmd", output_format = "pdf_document", output_file = "toPDF2.pdf")

我观察了监视器。生成几个 block 后,我开始看到多条消息,例如在几个 block 完成后如下所示。

*警告 (if (out_format(c("latex", "sweave", "listings", "markdown"))) sanitize_fn else str_c)(path, : 图形路径中的点替换为 _ ("IraAppliedStats_Rmd_files/figure-latex/unnamed-chunk-10")*

每个 block 都有以下消息。

没有 R 代码的普通文本

文档的大部分内容都是 R 代码。当我生成 HTML 文件时,会出现同一行。

错误消息的本质似乎是。

pandoc.exe:从 TeX 源生成 PDF 时出错。 这是 pdfTeX,版本 3.1415926-2.3-1.40.12(MiKTeX 2.9 64 位) pdflatex:找不到内存转储文件。

然后,我使用记事本将以下两行添加到 IraAppliedStats.md 文件的顶部。

*标题:IraAppliedStats.md 输出:pdf_文档*

我关闭了记事本。

我再次运行该命令。

render(input = "IraAppliedStats.Rmd", output_format = "pdf_document", output_file = "IraAppliedStats.Rmd.pdf")

这似乎没有帮助,因为我再次收到一条错误消息,并且没有生成 PDF 文件。

添加/编辑结束

最佳答案

使用rmarkdown package (包含在 RStudio 版本 0.98.682,the current preview release 中)将 Rmd 转换为 PDF 非常简单,只有一个函数可以完成转换:render。

这是我的 markdown 文件(在 RStudio 中启动新 Rmd 时创建的示例),假设它名为 Untitled.Rmd 并保存在工作目录中(并假设您的 LaTeX 发行版是完全是最新的,并且您拥有最新版本的 Pandoc):

--- title: "Untitled" # you must have lines similar to these in your Rmd file output: pdf_document # this is how R knows to convert this file to a PDF --- This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. Click the **Help** toolbar button for more details on using R Markdown. When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this: ```{r} summary(cars) ``` You can also embed plots, for example: ```{r, echo=FALSE} plot(cars) ``` Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

然后我在控制台中运行:

library(rmarkdown) render("Untitled.Rmd") # you could also use "Untitled.md"

然后我在工作目录中得到Untitled.pdf,如下所示:

或者,如果您无法使用该版本的 RStudio,或者不想包含这些 title: 和 output,这里是执行此操作的常用方法: Markdown 代码中的 行:

# Load packages. require(knitr) require(markdown) # Process your .Rmd and generate a .pdf file # (including smart punctuation and grey background of code blocks) # For this step you'll need to have two other programs installed on your computer # 1. Pandoc: http://johnmacfarlane.net/pandoc/installing.html # 2. LaTeX: follow the instructions on the Pandoc download page filen sessionInfo() R version 3.0.2 (2013-09-25) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] rmarkdown_0.1.4 loaded via a namespace (and not attached): [1] evaluate_0.5.1 formatR_0.10 knitr_1.5 stringr_0.6.2 tools_3.0.2 yaml_2.1.10

关于r - 使用 RStudio 将 *.md 转换为 *.pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22140742/



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有